﻿@using KC.Web.Account.Constants
@using KC.Framework.Extension
@model KC.DTO.Account.OrganizationDTO


<form class="easyui-form" method="post" id="saveform" action="@Url.Action(ActionName.Organization.SaveOrganizationForm, ControllerName.Organization)">
    @Html.AntiForgeryToken()
    @Html.HiddenFor(model => model.id)
    @Html.HiddenFor(model => model.Status)
    @Html.HiddenFor(model => model.Leaf)
    @Html.HiddenFor(model => model.Level)
    @Html.HiddenFor(model => model.TreeCode)
    @Html.HiddenFor(model => model.IsDeleted)
    @Html.HiddenFor(model => model.CreatedBy)
    @Html.HiddenFor(model => model.CreatedDate)
    @Html.HiddenFor(model => model.ModifiedBy)
    @Html.HiddenFor(model => model.ModifiedDate)

    <table class="dialog-form-table">
        <tbody>
            <tr>
                <td><label for="ParentId">父节点：</label></td>
                <td>
                    @if (Model.ParentId != 0 && Model.Level == 4)
                    {

                        <input id="ParentId" name="ParentId" class="easyui-textbox" value="@Model.Name" style="width: 200px;">
                    }
                    else
                    {
                        <input id="ParentId" name="ParentId" class="easyui-textbox" value="@Model.ParentId" style="width: 200px;">
                    }

                </td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="Name">名称：</label></td>
                <td><input id="text" name="text" class="easyui-validatebox easyui-textbox" data-options="required:true,width:200,validType:['length[2,15]','isSpace','validOrgValue[\'@Url.Action("ExistOrganizationName", ControllerName.Organization)\',\'name\',\'系统已存在该部门名称\']']" value="@(null != Model ? Model.text : string.Empty)" /></td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="PositionLevel">归属业务类型：</label></td>
                <td>
                    @Html.DropDownList("BusinessType", (IEnumerable<SelectListItem>)ViewBag.BusinessTypes, "请选择部门岗位", new Dictionary<string, object>
                        {
                        { "class","easyui-combobox" },
                        { "id", "BusinessType" },
                        { "data-options","editable: false, required:true" },
                        { "panelHeight","auto" },
                        { "style", "width:200px" }
                        })
                </td>
            </tr>
            <tr>
                <td><label class="required">*</label><label for="Index">排序：</label></td>
                <td><input id="Index" name="Index" class="easyui-numberspinner easyui-textbox" data-options="required:true,width:200,min:1,max:100" value="@(null != Model ? Model.Index : 0)"></td>
            </tr>
        </tbody>
    </table>
</form>
<script>

    $(function () {
        $('.textbox').bind('blur', function () {
            $(this).validatebox('enableValidation').validatebox('validate');
        });

        $('#ParentId').combotree({
            url: '@Url.Action(ActionName.Organization.LoadOrganizationOneLevelTree, ControllerName.Organization)',
            queryParams: {
                id: "@Model.id"
            },
            required: true
        });
    });


    $.extend($.fn.validatebox.defaults.rules, {
        validOrgValue: {
            validator: function (value, param) {
                var flag = true;
                var postData = {};
                postData[param[1]]= value;
                postData.Id = $('#id').val();
                $.ajax({
                    async: false,
                    type: 'POST',
                    dataType: 'json',
                    url: param[0],
                    data: postData,
                    success: function (result) {
                        if (result.toString() == "false") {
                            flag = false;
                        }
                    }
                });
                return flag;
            },
            message: '{2}'
        }
    });

</script>
